#include "StdAfx.h"
#include "SgMaterial.h"

CSgMaterial::CSgMaterial(float shininess, float diffuse[4], float specular[4])
{
	m_child = NULL;
	m_shininess[0] = shininess;
	for (int i=0;i<4;i++) m_diffuse[i]=diffuse[i];
	for (int i=0;i<4;i++) m_specular[i]=specular[i];
}

CSgMaterial::CSgMaterial(float shininess, float diffuse_R, float diffuse_G, float diffuse_B, float diffuse_A, float specular_R, float specular_G, float specular_B, float specular_A)
{
	m_child = NULL;
	SetMaterial(shininess, diffuse_R, diffuse_G, diffuse_B, diffuse_A, specular_R, specular_G, specular_B, specular_A);
}

void CSgMaterial::SetMaterial(float shininess, float diffuse_R, float diffuse_G, float diffuse_B, float diffuse_A, float specular_R, float specular_G, float specular_B, float specular_A)
{
	float d[4] = {diffuse_R, diffuse_G, diffuse_B, diffuse_A};
	float s[4] = {specular_R, specular_G, specular_B, specular_A};
	m_shininess[0] = shininess;
	for (int i=0;i<4;i++) m_diffuse[i]=d[i];
	for (int i=0;i<4;i++) m_specular[i]=s[i];
}

CSgMaterial::~CSgMaterial(void)
{
	//if (m_child != NULL)
	//	m_child->DecRef();
}

void CSgMaterial::Render()
{
	if (m_child != NULL)
	{
		glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat*)m_diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, (GLfloat*)m_specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, (GLfloat*)m_shininess);
		m_child->Render();
	}
}
